from yagmail import SMTP

from setting import config
from core.logger import logger


def email(to_users: list, subject: str, body: str, html: str = None, host=config.EMAIL_HOST, port=config.EMAIL_PORT,
          username=config.EMAIL_USERNAME, password=config.EMAIL_PASSWORD, smtp_ssl=True):
    yag = SMTP(host=host, user=username, password=password, port=port, smtp_ssl=smtp_ssl)
    try:
        yag.send(to=to_users, subject=subject, contents=[body, html])
        logger.info("send email success")
        return True
    except Exception as e:
        logger.error(f"send email error =>{e}")
        return False
